package com.gxa.eshop.portal.controller;

import com.gxa.eshop.core.pojo.User;
import com.gxa.eshop.core.utils.JsonResult;
import com.gxa.eshop.portal.thread.UserThreadLocal;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Resource
    RedisTemplate<String,Object> redisTemplate;

    private static final String CART = "cart:";

    @PostMapping("/add")
    public JsonResult addItem(@RequestParam Long itemId){
        //使用token和sso服务器校验
        // cart和order两个模块都需要先执行权限校验
        // 考虑用拦截器 interceptor

        // 通过封装的UserThreadLocal从当前线程中获取用户id
        User user = UserThreadLocal.get();

        Long id = user.getId();

        // id去redis中生成一个hash类型key:  购物车的元素, 添加商品id和num
        //CART+id
       // redisTemplate.opsForHash().put(CART+id,itemId);

        return null;
    }

}
